﻿using RTAids_From_Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using GemBox.Spreadsheet;


namespace RTAids_From_Report {
	class Program {
		static void Main(string[] args) {

			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			//		GET FILENAME FROM PARAMETER
			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
					
			string FileName = args[0];
			Console.WriteLine(FileName);
			if (FileName == "" || FileName == null) {
				Console.WriteLine("Must pass filename as parameter.... ");
				Console.ReadLine();

				Environment.Exit(1);
			}

			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			//		INITIATE EXCEL FILE OBJECT
			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			ExcelFile xl = new ExcelFile();


			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			//		LOAD THE REPORT SHEET
			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			xl.LoadXlsx(FileName, XlsxOptions.PreserveMakeCopy);
			ExcelWorksheet xls = xl.Worksheets[1];



			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			//		LOOP THROUGH LIST OF RTAS AND EXTRACT LINK
			//+++++++++++++++++++++++++++++++++++++++++++++++++++++
			int i = 2;

			while (xls.Cells[i, 1].Value != "" || xls.Cells[i,1].Value != null) {
				xls.Cells[i, 2].Formula = "=Right(Cells(i, 1), 6) & \"=\" & Right(Range(\"a\" & i).Hyperlinks(1).Address, Len(Range(\"a\" & i).Hyperlinks(1).Address) - 52)";
				i = i + 1;
			}



			Console.ReadLine();


		}
	}
}
